<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<%@ taglib prefix="fmt" uri="jakarta.tags.fmt" %>

<div class="admin-header">
    <button type="button" class="btn-primary" onclick="showAddQuoteModal()">添加名言</button>
</div>

<div class="admin-table">
    <table>
        <thead>
            <tr>
                <th>ID</th>
                <th>内容</th>
                <th>作者</th>
                <th>状态</th>
                <th>创建时间</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <c:forEach items="${quotes}" var="quote">
                <tr>
                    <td>${quote.id}</td>
                    <td>${quote.content}</td>
                    <td>${quote.author}</td>
                    <td>${quote.status == 1 ? '启用' : '禁用'}</td>
                    <td>${quote.formatted_create_time}</td>
                    <td>
                        <button type="button" class="btn-small" onclick="showEditQuoteModal(${quote.id})">编辑</button>
                        <button type="button" class="btn-small btn-danger" onclick="deleteQuote(${quote.id})">删除</button>
                    </td>
                </tr>
            </c:forEach>
        </tbody>
    </table>
</div>

<!-- 添加名言模态框 -->
<div id="addQuoteModal" class="modal">
    <div class="modal-content">
        <h3>添加名言</h3>
        <form id="addQuoteForm">
            <div class="form-group">
                <label>内容</label>
                <textarea name="content" rows="4" required></textarea>
            </div>
            <div class="form-group">
                <label>作者</label>
                <input type="text" name="author" required>
            </div>
            <div class="form-group">
                <label>状态</label>
                <select name="status">
                    <option value="1">启用</option>
                    <option value="0">禁用</option>
                </select>
            </div>
            <div class="form-actions">
                <button type="submit" class="btn-primary">保存</button>
                <button type="button" onclick="closeModal('addQuoteModal')" class="btn-danger">取消</button>
            </div>
        </form>
    </div>
</div>

<!-- 编辑名言模态框 -->
<div id="editQuoteModal" class="modal">
    <div class="modal-content">
        <h3>编辑名言</h3>
        <form id="editQuoteForm">
            <input type="hidden" name="id">
            <div class="form-group">
                <label>内容</label>
                <textarea name="content" rows="4" required></textarea>
            </div>
            <div class="form-group">
                <label>作者</label>
                <input type="text" name="author" required>
            </div>
            <div class="form-group">
                <label>状态</label>
                <select name="status">
                    <option value="1">启用</option>
                    <option value="0">禁用</option>
                </select>
            </div>
            <div class="form-actions">
                <button type="submit" class="btn-primary">保存</button>
                <button type="button" onclick="closeModal('editQuoteModal')" class="btn">取消</button>
            </div>
        </form>
    </div>
</div>

<script src="/static/js/admin-quotes.js"></script> 